public class Strings
{
   /**
      Gets the middle character or character pair from this string 
      when possible.
      @param str a string
      @return the middle character (if the string length is odd) or
      the middle two characters (if it is even), or the empty string if str is
      empty.
   */
   public static String getMiddle(String str)
   {
      int len = str.length();
      int middle = len / 2;
      int yu = len % 2;
      String yu1 = yu + "";
      String result = "";
      if(str.equals(""))
         result = "";
      else
      {
         if(yu == 0)
            result = str.substring(middle - 1, middle + 1);
         else
            result = str.charAt(middle) + "";
      }
      return result;
   }
}      